<?php

//ruta de imagenes
define("IMG_DELETE", "images/drop.png");
define("IMG_EDIT", "images/edit.png");

// parametros para opciones
define("PARAM_DEL", "del");
define("PARAM_TABLE", "table");
define("PARAM_ADD", "add");
define("PARAM_SELECT", "select");
define("PARAM_EDIT", "edit");

//Estilos para agregar y modificar
define("STYLE_OVERLAY", "visibility: hidden;position: absolute;left: 0px;top: 0px; width:100%;height:100%;text-align:center;z-index: 1000;");
define("STYLE_WIN", "width:300px;margin: 150px auto;background-color: #fff;border:2px solid cornflowerblue;padding:15px;text-align:center; border-radius:8px;box-shadow: 1px 1px 12px #555; ");


define("STYLE_TABLE", "border: #DDEEFF 2px solid;border-radius:8px;background-color:#DDEEFF; 'align=center width=100%");
define("STYLE_TABLE_HEADER", "background-color:#DDEEFF;text-align:center;");
define("STYLE_TABLE_HEADER_CELL", "padding:5px 5px 5px 5px;font-weight: bold;");
define("STYLE_TABLE_LINE", "background-color:#FFFFFF;");
define("STYLE_HIDDEN","display:none");

define("STYLE_TEXT_ADD", "display: block;color:orange;font-weight: bold ");
define("TYPE_NUMBER", "' onKeypress='if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;'");
define("TYPE_FLOAT", "' onKeypress='if (event.keyCode != 46 && (event.keyCode < 48 || event.keyCode > 57) ) event.returnValue = false;'");

class DataGrid_2 {

    private $param = array(PARAM_DEL, PARAM_EDIT, PARAM_SELECT, PARAM_ADD, PARAM_TABLE);
    private $ConnexionPDO;
    private $Table = "";
    private $Clave_Primaria = "";
	private $WhereClause = "";
    
    private $Nom_Cols = array();
    private $Type_Cols = array();
    private $Cell_Property = array();
    private $Col_Title = array();
    private $Col_Type = array();
    private $Field_Day = array();
    private $Field_Hour = array();
    
    private $ModeAdd = false;
    private $ModeDelete = false;
    private $ModeEdit = false;
    
    private $visiblePK = false;
    private $posPK = 0;
    
    private $selectCol = "*";
    //para manejo de maestro-detalle, y mostrar textos de maestro
    private $detailName = array();
    private $detailStmt = "";    
    /**
     * Constructor de la clase.
     * @param String $cols  Columnas deseadas, separadas por comas.  * para seleccionar todas.
     * @param PDO $connexion Conexion PDO.
     */
    public function __construct($table=NULL, $cols="*", $where=NULL, PDO $connexion=NULL) {
        $this->ConnexionPDO = $connexion;
        $this->ConnexionPDO->query("SET NAMES 'utf8'");

        $this->Table = $table;
        $this->selectCol = $cols;
		$this->WhereClause = $where;

        $req = "select ".$this->GetSelect()." from " . $this->Table . " ". $this->WhereClause . " limit 0,1";

        $resultat = $this->ConnexionPDO->query($req);
        $Nb_Col = $resultat->columnCount();

        for ($i = 0; $i < $Nb_Col; $i++) {
            $Name_Col = $resultat->getColumnMeta($i); 

            //Encontrar la clave primaria 
            if (isset($Name_Col['flags'][1]) && $Name_Col['flags'][1] == "primary_key") {
                $this->Clave_Primaria = $Name_Col['name'];
                $this->SetPosPK($i);  //setea posicion de la PK
            }
            //Obtener los nombres de las columnas   
            $this->Nom_Cols[] = $Name_Col['name'];
            $this->Col_Title[$i] = $this->TextFormat($Name_Col['name']);            
            
            //Obtener los tipos de las columnas   
            $this->Type_Cols[] = $Name_Col['native_type'];
        }
    }
   
    private function GetSelect(){
        return $this->selectCol;        
    }
	/**
     * Sobreescribe el nombre de las columnas.  Permite personalizar el titulo.
     * @param int $Pos     Posicion de la columna a partir de 0.
     * @param string $Value   Titulo personalizado.
     */
    public function SetWhereClause($Value){
        $this->WhereClause = $Value;
    }
    /**
     * Sobreescribe el nombre de las columnas.  Permite personalizar el titulo.
     * @param int $Pos     Posicion de la columna a partir de 0.
     * @param string $Value   Titulo personalizado.
     */
    public function SetNameColumn($Pos, $Value){
        $this->Col_Title[$Pos] = $Value;
    }
    /**
     * Determina el tipo de la columna para permitir el ingreso de datos especificos.
     * @param int $Pos     Posicion de la columna a partir de 0.
     * @param string $Value   Tipo.
     */
    public function SetTypeColumn($Pos, $Value){
        $this->Col_Type[$Pos] = $Value;
    }
    /**
     * Determina que el campo es de dia de semana para mostrarse como checkbox.
     * @param int $Pos     Posicion de la columna a partir de 0.
     * @param boolean $Value  
     */
    public function SetDayField($Pos, $Value){
        $this->Field_Day[$Pos] = $Value;
    }  
    /**
     * Determina que el campo es de hora
     * @param int $Pos     Posicion de la columna a partir de 0.
     * @param boolean $Value   Tipo.
     */
    public function SetHourField($Pos, $Value){
        $this->Field_Hour[$Pos] = $Value;
    }
    /**
     * Setear si se desea visualizar la llave primaria (PK)
     * @param boolean $Value True: se visualizara la columna de la PK
     */
    public function SetVisiblePK($Value){
        $this->visiblePK = $Value;
    }
    
    private function GetVisiblePK(){
        return $this->visiblePK;
    }
    
    private function GetPK(){
        return $this->Clave_Primaria;
    }    

    private function SetPosPK($Value){
        $this->posPK = $Value;
    }
    
    private function GetPosPK(){
        return $this->posPK;
    }
    /**
     * Agregar cadena con propiedades para la celda
     * @param int $Pos      Numero de columna.
     * @param String $Value Cadena con la propiedades (Ej. align=right width=10%)     
     */
    public function SetCellProperty($Pos, $Value){
        $this->Cell_Property[$Pos] = $Value;
    }
    
    private function GetCellProperty($Pos){        
        return $this->Cell_Property[$Pos];
    }
    /**
     * Colocar los valores de la tabla de referencia
     * @param type $FK      Nombre de la columna que tiene la referencia (FK)
     * @param type $FCol    Columna de la otra tabla que equivale a la FK
     * @param type $NCol    Columna de la otra tabla que contiene el nombre
     * @param type $Table   Tabla a la que se hace referencia
     * @param type $Title   Titulo deseado para la columna que tiene la referencia al momento de editar
     */
    public function SetDetailName($FK, $FCol, $NCol, $Table ,$Title){
        $this->detailName[$FK] = array($FCol, $NCol, $Table, $Title);        
    }
    
    private function GetDetailColumnFK($Value){
        return $this->detailName[$Value][0];
    }
    
    private function GetDetailColumnName($Value){
        return $this->detailName[$Value][1];
    }
    
    private function GetDetailTable($Value){
        return $this->detailName[$Value][2];
    }
    
    private function GetDetailTitle($Value){
        return $this->detailName[$Value][3];
    }


    public function SetDetailStmt($Value){
        $this->detailStmt = $Value;
    }

    public function GetTable() {
        return $this->Table;
    }

    public function SetTable($Value) {
        $this->Table = $Value;
    }

    public function GetConnexionPDO() {
        return $this->ConnexionPDO;
    }

    public function SetConnexionPDO($Value) {
        $this->ConnexionPDO = $Value;
    }
    /**
     * Ver opcion para ingreso nuevo.
     * @param boolean $Value   Visualizar opcion para nuevos ingresos.
     */
    public function SetModeAdd($Value) {
        $this->ModeAdd = $Value;
    }
    /**
     * Ver opcion para eliminar registro.
     * @param boolean $Value    Visualizar opcion para eliminar registros.
     */
    public function SetModeDelete($Value) {
        $this->ModeDelete = $Value;
    }
    /**
     * Ver opcion para editar registro.
     * @param boolean $Value    Visualizar opcion para editar registros.
     */
    public function SetModeEdit($Value) {
        $this->ModeEdit = $Value;
    }

    public function GetModeAdd() {
        return $this->ModeAdd;
    }

    public function GetModeDelete() {
        return $this->SetModeDelete;
    }

    public function GetModeEdit() {
        return $this->ModeEdit;
    }

    private function URL_Param() {

        //recuperar la dirección URL de la página con estos parámetros
        $link = "";
        foreach ($_GET as $key => $value) {
            if (!in_array($key, $this->param)) {
                $link = $link == "" ? "" : $link . "&";
                $link = $link . $key . "=" . $value;
            }
        }
        $link = $link == "" ? "" : "?" . $link;
        return $link;
    }
    
    private function ActivationModeAdd() {

        //echo "<a href='#' style='" . STYLE_TEXT_ADD . "' onclick='overlay()'>Ingresar nuevo</a></br>";
        //echo "<input type='button' value='Ingresar nuevo' onclick='overlay_".$this->Table."()'/>";
        echo "<p><a href='#' class='links' onclick='overlay_".$this->Table."()'>NUEVO</a><p>";

        echo "<script language='javascript'>";
        echo " function overlay_".$this->Table."() {";
        echo " el = document.getElementById('overlay_".$this->Table."');";
        echo " el.style.visibility = (el.style.visibility == 'visible') ? 'hidden' : 'visible';}";
        echo " </script>";

        echo "<div id='overlay_".$this->Table."' style='" . STYLE_OVERLAY . "'>";
        echo "<div style='" . STYLE_WIN . "'>";

        echo "<form name='form_add' method='post' action='" . $_SERVER['PHP_SELF'] . $this->URL_Param() . "'><table>";
        $i = 0;
        foreach ($this->Nom_Cols as $col) {
            if (!$this->GetVisiblePK() && $this->GetPK() == $col) {
            }else if ($this->GetDetailColumnFK($col)) {  //$this->detailName[$col][0] //$col == 'puesto_id_puesto'
                
                $req = "select ".$this->GetDetailColumnFK($col).",".$this->GetDetailColumnName($col)." from ".$this->GetDetailTable($col); //$this->detailName[$col][0]//$req = "select id_puesto, nombre from puesto";
                $resultat = $this->ConnexionPDO->query($req);                
                echo "<tr>";
                echo "<td>".$this->TextFormat($this->GetDetailTitle($col))."</td>";
                echo "<td>:</td>";             
                
                echo "<td><SELECT name='" . $col . "' onChange = 'document.form_add.submit()' >";
                foreach ($resultat as $row){
                    echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
                }                 				
		echo "</SELECT></td>";
                echo "</tr>";
                
            }else if($this->Field_Day[$i]){ //es campo de dia de la semana
                if($col == "lun"){
                    echo "<td></td>";
                    echo "</table>";
                    echo "<table>";
                    echo "<tr>";
                    echo "<td>LUN</td><td>MAR</td><td>MIE</td><td>JUE</td><td>VIE</td><td>SAB</td><td>DOM</td>";
                    echo "</tr>";
                    echo "<tr>";
                }                
                echo "<td><input type='checkbox' name='" . $col . "' value='x' /></td>";  
                if($col == "dom"){
                    echo "</tr>";
                    echo "<td></td>";
                    echo "</table>";
                    echo "<table>";
                }                                
            }else if($this->Field_Hour[$i]){ //es campo de hora
                echo "<tr>";
                echo "<td>".$this->Col_Title[$i]."</td>";
                echo "<td>:</td>";
                echo "<td><SELECT name='" . $col . "'>";                    
                for ($hr = 7; $hr <= 21; $hr++) {
                    echo "<option value='" . $hr . ":00:00'>" . $hr . ":00 hrs.</option>";
                }                
		echo "</SELECT></td>";
                echo "</tr>";                                
            }else{                
                echo "<tr>";
                echo "<td>" . $this->Col_Title[$i] . "</td>"; //$this->TextFormat($col)
                echo "<td>:</td>";
                echo "<td><input type='text' name='" . $col . "' '". $this->Col_Type[$i] . " /></td>";
                echo "</tr>";
            }
            $i++;
        }
        echo "<td></td>";
        echo "<td><input type='hidden' name='action' value='add' /></td>";
        echo "<td><input type='submit' value='Aceptar'/> <input type='button' value='Cancelar' onclick='overlay_".$this->Table."()'/></td>";
        echo "</table></form></div></div>";
    }

    private function Add() {
        $col = "";
        $val = "";

        foreach ($_POST as $key => $value) {
            if ($key != "action") {
                $col = $col == "" ? "`" . $key . "`" : $col . ", `" . $key . "`";
                $val = $val == "" ? "'" . $value . "'" : $val . ", '" . $value . "'";
            }
        }
        $req = "INSERT INTO " . $this->Table . " (" . $col . ") VALUES (" . $val . ");";
        //echo "INSERT INTO ".$this->Table." (".$col.") VALUES (".$val.");";
        $this->ConnexionPDO->exec($req); //or die(print_r( $this->ConnexionPDO->errorInfo())) 
        //$_POST["action"]= "done";
        //echo "<form name='frm_done' method='post' action='done'></form>";
        //unset($_POST["action"]);
    }

    private function ActivationModeEdit($row) {
        echo "<td style='text-align:center'>";
        echo "<a href='#' onclick='overlay_edit_".$this->Table."(\"" . $row . "\")'>";
        echo "<img src='" . IMG_EDIT . "' alt='Editar'/>";
        echo "</a>";
        echo "</td>";
    }

    private function ActivationModeEditShowModal() {
        echo "<script language='javascript'>";
        echo " function overlay_edit_".$this->Table."(r_".$this->Table.") {";
        echo " el = document.getElementById('overlay_edit_".$this->Table."');";
        echo " el.style.visibility = (el.style.visibility == 'visible') ? 'hidden' : 'visible';";
        for ($i = 0; $i < sizeof($this->Nom_Cols); $i++) {

            echo " document.forms['frm_edit_".$this->Table."'].elements['" . $this->Nom_Cols[$i] . "'].value=document.getElementById(r_".$this->Table.").cells[" . $i . "].innerHTML;";
        }
        echo " }</script>";

        echo "<div id='overlay_edit_".$this->Table."' style='" . STYLE_OVERLAY . "'>";
        echo "<div style='" . STYLE_WIN . "'>";

        echo "<form name='frm_edit_".$this->Table."' method='post' action='" . $_SERVER['PHP_SELF'] . $this->URL_Param() . "'><table>";
        $i = 0;
        foreach ($this->Nom_Cols as $col) {
            if (!$this->GetVisiblePK() && $this->GetPK() == $col) {
                echo "<tr style='" . STYLE_HIDDEN . "'>";
                echo "<td>" . $this->TextFormat($col) . "</td>";
                echo "<td>:</td>";
                echo "<td><input type='text' name='" . $col . "'/></td>";
                echo "</tr>";                
            }else if ($this->GetDetailColumnFK($col)) {  //$col == 'puesto_id_puesto'
                
                $req = "select ".$this->GetDetailColumnFK($col).",".$this->GetDetailColumnName($col)." from ".$this->GetDetailTable($col); //$this->detailName[$col][0]//$req = "select id_puesto, nombre from puesto";
                $resultat = $this->ConnexionPDO->query($req);                
                echo "<tr>";
                echo "<td>".$this->TextFormat($this->GetDetailTitle($col))."</td>";
                echo "<td>:</td>";             
                
                echo "<td><SELECT name='" . $col . "'>";
                foreach ($resultat as $row){
                    echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
                }                 				
		echo "</SELECT></td>";
                echo "</tr>";
                
            }else if($this->Field_Day[$i]){  //es campo de dia
                if($col == "lun"){
                    echo "<td></td>";
                    echo "</table>";
                    echo "<table>";
                    echo "<tr>";
                    echo "<td>LUN</td><td>MAR</td><td>MIE</td><td>JUE</td><td>VIE</td><td>SAB</td><td>DOM</td>";
                    echo "</tr>";
                    echo "<tr>";
                }                
                echo "<td><input type='checkbox' name='" . $col . "' value='x' /></td>";  
                if($col == "dom"){
                    echo "</tr>";
                    echo "<td></td>";
                    echo "</table>";
                    echo "<table>";
                }                                
            }else if($this->Field_Hour[$i]){ //es campo de hora
                echo "<tr>";
                echo "<td>".$this->Col_Title[$i]."</td>";
                echo "<td>:</td>";
                echo "<td><SELECT name='" . $col . "'>";                    
                for ($hr = 7; $hr <= 21; $hr++) {
                    echo "<option value='" . $hr . ":00:00'>" . $hr . ":00 hrs.</option>";
                }                
		echo "</SELECT></td>";
                echo "</tr>";                                
            }else{
                echo "<tr>";
                echo "<td>" . $this->Col_Title[$i] . "</td>";
                echo "<td>:</td>";
                echo "<td><input type='text' name='" . $col . "' '". $this->Col_Type[$i] . " /></td>";
                echo "</tr>";
            }    
            $i++;
        }
        echo "<td></td>";
        echo "<td><input type='hidden' name='action' value='edit' /></td>";
        echo "<td><input type='submit' value='Aceptar'/> <input type='button' value='Cancelar' onclick='overlay_edit_".$this->Table."()'/></td>";
        echo "</table></form></div></div>";
    }

    private function Edit() {
        $val = "";

        if (($this->Table == "horario_docente") || ($this->Table == "horario_curso")) { //si es tabla de horarios
            foreach ($_POST as $key => $value) {
                if ($key != "action") {
                    if(($key == "lun")||($key == "mar")||($key == "mie")||($key == "jue")||($key == "vie")||($key == "sab")||($key == "dom")){
                        if($value == "")$value = "x";
                    }
                    $col = $col == "" ? "`" . $key . "`" : $col . ", `" . $key . "`";
                    $val = $val == "" ? "'" . $value . "'" : $val . ", '" . $value . "'";
                }
            }
            $this->Delete($_POST[$this->Clave_Primaria]);
            //echo "INSERT INTO " . $this->Table . " (" . $col . ") VALUES (" . $val . ");";
            $req = "INSERT INTO " . $this->Table . " (" . $col . ") VALUES (" . $val . ");";
        } else {
            foreach ($_POST as $key => $value) {
                if ($key != "action") {                    
                    $val = $val == "" ? "" . $key . "='" . $value . "'" : $val . "," . $key . "='" . $value . "'";
                }
            }
            //echo "UPDATE " . $this->Table . " SET " . $val . " WHERE " . $this->Clave_Primaria . "='" . $_POST[$this->Clave_Primaria] . "'";
            $req = "UPDATE " . $this->Table . " SET " . $val . " WHERE " . $this->Clave_Primaria . "='" . $_POST[$this->Clave_Primaria] . "'";
        }

        $this->ConnexionPDO->exec($req); //or die(print_r( $this->ConnexionPDO->errorInfo())) 
    }

    private function ActivationModeDelete($Clave, $Tab) {

        $url = $this->URL_Param();
        $url = $url != "" ? $url . "&" . PARAM_TABLE . "=" . $Tab . "&" . PARAM_DEL . "=" . $Clave : $url . "?" . PARAM_TABLE . "=" . $this->Table . "&" . PARAM_DEL . "=" . $Clave;
        $url = $_SERVER['PHP_SELF'] . $url;

        echo "<td style='text-align:center'>";
        echo "<a href='" . $url . "'>";
        echo "<img src='" . IMG_DELETE . "' alt='Borrar'/>";
        echo "</a>";
        echo "</td>";
    }

    private function Delete($id) {
        $this->ConnexionPDO->exec("delete from " . $this->Table . " where " . $this->Clave_Primaria . "=" . $id);
		//echo "delete from " . $this->Table . " where " . $this->Clave_Primaria . "=" . $id;
    }

    private function TextFormat($str) {
        return strtoupper(str_replace("_", " ", $str));
    }
    
    private function GetJoin($Col, $Value){
        $req = "select ".  $this->GetDetailColumnName($Col)." from " . $this->GetDetailTable($Col). " where ". $this->GetDetailColumnFK($Col) . " = ". $Value . " limit 1";
        //echo $req;
        $resultat = $this->ConnexionPDO->query($req);
        foreach ($resultat as $row) {
            return $row[0];
        }
    }
    
    public function GetAsArray(){
        $arrData = array();
       
        $req = "select ".$this->GetSelect()." from " . $this->Table . " ". $this->WhereClause;
        $resultat = $this->ConnexionPDO->query($req);
        $Nb_Col = $resultat->columnCount();
        $Name_Col = array();
                        
        $j = 1;
        foreach ($resultat as $row) {   
            //array_push($arrData, $row);
            $arrD = array();
            for ($i = 0; $i < $Nb_Col; $i++) {                 
                $Name_Col[$i] = $resultat->getColumnMeta($i);
                if(!$this->GetVisiblePK() && $this->GetPosPK() == $i)
                    null;
                else if($this->GetDetailColumnFK ($Name_Col[$i]['name'])){
                    //array_push($arrD, array($this->TextFormat($this->GetJoin($Name_Col[$i]['name'], $row[$i]))=>$row[$i]));                    
                    //array_push($arrD, array($this->TextFormat($this->GetJoin($Name_Col[$i]['name'], $row[$i]))=>$row[$i]));
                    $arrD[$this->Nom_Cols[$i]] = $this->GetJoin($Name_Col[$i]['name'], $row[$i]);
                }                    
                else
                    $arrD[$this->Nom_Cols[$i]] = $row[$i];
                    //aarray_push($arrD, array($this->TextFormat($this->Nom_Cols[$i])=>$row[$i]));    
                    //array_push($arrD, array($this->TextFormat($this->Nom_Cols[$i])=>$row[$i]));        
                    //null;
            }
            $j++;
            array_push($arrData,$arrD);
        }
        return $arrData;
    }

    /**
     * Desplegar la tabla con las propiedades definidas.
     */
    public function Show() {
        if ($this->ModeEdit)
            $this->ActivationModeEditShowModal();
        if (isset($_GET[PARAM_DEL]) && $_GET[PARAM_DEL] != "")
            $this->Delete($_GET[PARAM_DEL], $_GET[PARAM_TABLE]);
        if (isset($_POST["action"]) && $_POST["action"] == "add")
            $this->Add();
        if (isset($_POST["action"]) && $_POST["action"] == "edit")
            $this->Edit();

        if($this->detailStmt == "")
            $req = "select ".$this->GetSelect()." from " . $this->Table . " ". $this->WhereClause;
        else
            $req = $this->detailStmt;
        //$req = "select i.id_instructor, p.nombre, i.nombre, i.apellido, i.telefono, i.email from asignacion.puesto p, asignacion.instructor i where p.id_puesto = i.puesto_id_puesto";
        $resultat = $this->ConnexionPDO->query($req);
        $Nb_Col = $resultat->columnCount();
        $Name_Col = array();

        if ($this->ModeAdd)
            $this->ActivationModeAdd();

        /* imprimir la tabla */
        echo "<table style='" . STYLE_TABLE . "'>";
        echo"<tr style='" . STYLE_TABLE_HEADER . "'>";

        for ($i = 0; $i < $Nb_Col; $i++) {  //recorre las columnas
            $Name_Col[$i] = $resultat->getColumnMeta($i); 
            if(!$this->GetVisiblePK() && $this->Nom_Cols[$i] == $this->GetPK() ){ //no se desea visualizar la PK
                echo "<td style='" . STYLE_HIDDEN . "'>" . $this->TextFormat($this->Nom_Cols[$i]) . "</td>";
            }
            else
                echo "<td style='" . STYLE_TABLE_HEADER_CELL . "'>" . $this->Col_Title[$i] . "</td>";
        }
        if ($this->ModeEdit)
            echo "<td style='" . STYLE_TABLE_HEADER_CELL . "'>  </td>"; //editar
        if ($this->ModeDelete)
            echo "<td style='" . STYLE_TABLE_HEADER_CELL . "'>  </td>"; //eliminar
        echo"</tr>";
        
        $j = 1;
        foreach ($resultat as $row) {
            echo"<tr id='row_".$this->Table."" . $j . "' style='" . STYLE_TABLE_LINE . "'>";
            for ($i = 0; $i < $Nb_Col; $i++) {
                if(!$this->GetVisiblePK() && $this->GetPosPK() == $i)
                    echo "<td style='" . STYLE_HIDDEN . "'>" . $row[$i] . "</td>";
                else if($this->GetDetailColumnFK ($Name_Col[$i]['name'])){
                    //echo "<td style='" . STYLE_HIDDEN . "'>" . $row[$i] . "</td>";
                    echo "<td ". $this->GetCellProperty($i) .">" . $this->GetJoin($Name_Col[$i]['name'], $row[$i]) . "</td>";
                }                    
                else
                    echo "<td ". $this->GetCellProperty($i) .">" . $row[$i] . "</td>";
            }
            if ($this->ModeEdit)
                $this->ActivationModeEdit("row_".$this->Table."" . $j);
            if ($this->ModeDelete)
                $this->ActivationModeDelete($row[$this->Clave_Primaria]);
            echo"</tr>";
            $j++;
        }

        echo "</table>";
    }

}

?>

